from google.appengine.ext import db
from google.appengine.api import users

class Person(db.Model):
  name = db.StringProperty()
  user = db.UserProperty()
  emails = db.StringListProperty()
  paypal = db.StringProperty()
  image = db.BlobProperty()
  auth = db.StringProperty()
  
class PersonCookie(db.Model):
  person = db.ReferenceProperty(Person, required=True)
  cookie = db.StringProperty(required=True)
  expiry = db.DateTimeProperty(required=True)
  
class Contact(db.Model):
  person = db.ReferenceProperty(Person, collection_name='contact_set')
  knows = db.ReferenceProperty(Person, collection_name='contact_knows_set')
  last_accessed = db.DateTimeProperty()
  
class Expense(db.Model):
  creditor = db.ReferenceProperty(Person)
  debitors = db.ListProperty(db.Key) # Person
  portions = db.ListProperty(long)
  extras = db.ListProperty(long)
  amount = db.FloatProperty()
  date = db.DateProperty()
  # meta data
  location = db.StringProperty()
  description = db.StringProperty()
  tags = db.StringProperty()
  currency = db.StringProperty()
  # expense state
  requested = db.BooleanProperty()
  paid = db.BooleanProperty()
  
class Payment(db.Model):
  creditor = db.ReferenceProperty(Person, required=True, collection_name='credited_payment_set')
  debitor = db.ReferenceProperty(Person, required=True, collection_name='debited_payment_set')
  expenses = db.ListProperty(db.Key) # Person
  total = db.FloatProperty(required=True)
  paid = db.BooleanProperty(default=False)
  credited = db.BooleanProperty(default=False)
  